package com.team.ssm_item_lj.service.impl;

import com.team.ssm_item_lj.entity.RecyclingStations;
import com.team.ssm_item_lj.dao.RecyclingStationsDao;
import com.team.ssm_item_lj.service.RecyclingStationsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 回收站表(RecyclingStations)表服务实现类
 *
 * @author zhuxhenxin
 * @since 2024-12-05 10:44:30
 */
@Service("recyclingStationsService")
public class RecyclingStationsServiceImpl implements RecyclingStationsService {
    @Resource
    private RecyclingStationsDao recyclingStationsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public RecyclingStations queryById(Integer id) {
        return this.recyclingStationsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param recyclingStations 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RecyclingStations> queryByPage(RecyclingStations recyclingStations, PageRequest pageRequest) {
        long total = this.recyclingStationsDao.count(recyclingStations);
        return new PageImpl<>(this.recyclingStationsDao.queryAllByLimit(recyclingStations, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param recyclingStations 实例对象
     * @return 实例对象
     */
    @Override
    public RecyclingStations insert(RecyclingStations recyclingStations) {
        this.recyclingStationsDao.insert(recyclingStations);
        return recyclingStations;
    }

    /**
     * 修改数据
     *
     * @param recyclingStations 实例对象
     * @return 实例对象
     */
    @Override
    public RecyclingStations update(RecyclingStations recyclingStations) {
        this.recyclingStationsDao.update(recyclingStations);
        return this.queryById(recyclingStations.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.recyclingStationsDao.deleteById(id) > 0;
    }
}
